import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// =====================================================================Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const Button 	= $Lazy.load(()=>import('@antd/button'))
const SaoImage 	= $Lazy.load(()=>import('#tp/sao'))

const statusData = [{name:'待分发',value:'0'},{name:'不可分发',value:'-1'},{name:'已分发',value:'1'}]
// ===================================================================== component
const afterSuffix = <SaoImage />
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		// 搜索表单列表
		formData : [
			{ label:'原标本箱条码',		name: 'old_box_code', half:true,	max:6,	 p:'请扫描或输入条码号', required:true, afterSuffix,	
				onValue:({value})=>{
					if(value.length === 6){this.getBoxSpec(value)}
				}
			},
			{ label:'新标本箱条码',		name: 'new_box_code', half:true,	max:6,	 p:'请扫描或输入条码号', required:true, afterSuffix,
				onValue:({value})=>{
					if(value.length === 6){this.getBoxSpec(value)}
				}
			 }
		],
	}
	box_code = ''
	
	// 获取标箱体条码数据
	getBoxSpec = (value)=>{
		$http.pull(this,'box/specCodeInfo', { param: {box_code: value} })
	}
	
	// 表单
	cols = [
		{ title: '条码号', 			dataIndex: 'spec_code', 	...$fn.table.spec_code },
		{ title: '送检单位', 		dataIndex: 'hosp_name', 	width:200 },
		{ title: '送检地址', 		dataIndex: 'address', 		width:200 },
		{ title: '状态', 			dataIndex: 'spec_status', 	width:100, render:text=>$fn.getState(statusData,text) },
	]
	
	// 操作按钮
	controls = () => {
		return [
			Controls.back.call(this )
		]
	}
	
	render(){
		return (
			<Page title='整箱转移' controls={this.controls()}>
				{/* 提交 */}
				<div className='pt20 fx'>
					<div className='mr30'  style={{width:'60%'}}>
						{ SubmitForm.call(this,{ labelWidth:'s11', api:'box/allMove', onOk:({ data })=> {
							this.setState({ data })
						} }) }
					</div>
					<Button label='确认' size='middle' onClick={()=>this.formRef.submit()} />
				</div>
				<div className='f12 xplr mb20' style={{color:'red'}}>提示：当前列表中展示的条码信息为新标本箱条码信息</div>
				{/* 表格 */}
				{ Table.call(this, { type: -1 }) }
			</Page>
		)
	}
}

export default Index